# -*- coding: utf-8 -*-
# @Time : 2022/7/24 11:24
# @Author : WangYunfei
# @FileName: dy.py
# @Email: lxb_wyf@163.com
"""
红人点击 抖音榜单数据获取  -- sha256
"""
import hashlib
import json
import time

import requests


class DY(object):

    def __init__(self):
        self.url = "https://ucp.hrdjyun.com:60359/api/dy"
        self.headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
        }

    def js(self, n, e):
        """
         function E(n, e) {
            return k("param=" + JSON.stringify(n) + "&timestamp=" + e + "&tenant=1&salt=" + C)
        }
        :return:
        """
        _data = "param=" + n + "&timestamp=" + e + "&tenant=1&salt=" + "kbn%&)@<?FGkfs8sdf4Vg1*+;`kf5ndl$"
        return hashlib.sha256(_data.encode('utf-8')).hexdigest()

    @staticmethod
    def param():
        """"""
        # 直播分析
        # #  抖音实时热门直播 dy3009
        return json.dumps({"no": "dy3009", "data": {}})

    def spider(self):
        param = self.param()
        timestamp = int(time.time() * 1000)
        _data = {
            "param": param,
            "sign": self.js(param, str(timestamp)),
            "tenant": "1",
            "timestamp": timestamp,
            "token": "NAegUxPw2J7GbVrSElIZQoEX5yQkBzjm"
        }
        try:
            res = requests.post(url=self.url, json=_data, headers=self.headers).json()
            return res
        except Exception as e:
            print(f"红人点击数据获取失败--{_data}")
            return None


if __name__ == '__main__':
    print(DY().spider())







